// pages/mine/mine.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    user_img: "../../images/tb53.png",
    user_img2: "../../images/tb36.png",
    jiantou_img: "../../images/tb60.png",
    orderList: [{
        title: "抢购订单",
        more: "查看更多订单",
        list: [{
            img: "../../images/tb56.png",
            title: "待付款"
          },
          {
            img: "../../images/tb57.png",
            title: "待发货"
          }, {
            img: "../../images/tb59.png",
            title: "待收货"
          }, {
            img: "../../images/tb152.png",
            title: "待评价"
          }
        ]
      },
      {
        title: "拼团订单",
        more: "查看更多订单",
        list: [{
            img: "../../images/tb56.png",
            title: "待付款"
          },
          {
            img: "../../images/tb57.png",
            title: "待发货"
          }, {
            img: "../../images/tb59.png",
            title: "待收货"
          }, {
            img: "../../images/tb152.png",
            title: "待评价"
          }
        ]
      }
    ],
    itemList: [{
        img: "../../images/team.png",
        title: "我的团队"
      },
      {
        img: "../../images/tb66.png",
        title: "地址管理"
      }, {
        img: "../../images/tb67.png",
        title: "邀请好友"
      }, {
        img: "../../images/tb68.png",
        title: "客服"
      },
      {
        img: "../../images/tb133.png",
        title: "参与拼团"
      },
      {
        img: "../../images/tb132.png",
        title: "发起拼团"
      }, {
        img: "../../images/tb130.png",
        title: "帮助中心"
      }, {
        img: "../../images/tb131.png",
        title: "关于我们"
      }
    ],
    thumbUrl: getApp().globalData.thumbUrl,
    show: false,
    userInfo: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    wx.hideShareMenu
  },


  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    var uid = wx.getStorageSync('uid');
    if (uid) {
      var show = true;
      var param = {
        uid: uid
      };
      app.wxRequest('POST', "Index/getCenterInfo", param, (res) => {
        var data = res.data;
        // console.log(data)
        that.setData({
          userInfo: data
        })
      }, (err) => {
        console.log(err.errMsg)
      })
    } else {
      var show = false;
    }
    console.log(show)
    that.setData({
      show: show
    })
  },
  getUserInfo: function () {
    wx.navigateTo({
      url: '../authorization/authorization',
    })
  },
  teamList: function (e) {
    console.log(e)
    var that = this;
    var uid=wx.getStorageSync('uid')
    var type = e.currentTarget.dataset.type;
    if(uid){
      if (type == 0) {
        wx.navigateTo({
          url: '../team/team',
        })
      } else if (type == 1) {
        wx.navigateTo({
          url: '../address/address?type=2',
        })
      } else if (type == 2) {
        wx.navigateTo({
          url: '../content/content?type=1',
        })
      } else if (type == 4) {
        wx.navigateTo({
          url: '../joinGroup/joinGroup',
        })
      } else if (type == 5) {
        wx.navigateTo({
          url: '../launch/launch',
        })
      } else if (type == 6) {
        wx.navigateTo({
          url: '../content/content?type=2',
        })
      } else if (type == 7) {
        wx.navigateTo({
          url: '../content/content?type=3',
        })
      }
    }else{
      wx.navigateTo({
        url: '../authorization/authorization',
      })
    }
    
    
    // console.log(e)
  },
  tocollect: function () {
    var that = this;
    var uid=wx.getStorageSync('uid');
    if(uid){
      wx.navigateTo({
        url: '/pages/collect/collect',
      })
    }else{
      wx.navigateTo({
        url: '../authorization/authorization',
      })
    }
   
  },

  // /**
  //  * 用户点击右上角分享
  //  */
  // onShareAppMessage: function () {

  // },
  towallet() {
    var that = this;
    var uid=wx.getStorageSync('uid')
    if(!uid){
      wx.navigateTo({
        url: '../authorization/authorization',
      })
    }else{
      wx.navigateTo({
        url: '/pages/wallet/wallet',
      })
    }
   
  },
  toOrder(e) {
    let type = e.currentTarget.dataset.index
    let active = e.currentTarget.dataset.ind
    var uid = wx.getStorageSync('uid');
    if (uid) {
      if (type == 1) {
        wx.navigateTo({
          url: '/pages/robOrderList/robOrderList?active=' + active,
        })
      } else if (type == 2) {
        wx.navigateTo({
          url: '/pages/order/order?&active=' + active,
        })
      }
    } else {
      wx.navigateTo({
        url: '../authorization/authorization',
      })
    }


  },
  getPhoneInfo: function (e) {
    var that = this;
    var uid = wx.getStorageSync('uid');
    if (e.detail.errMsg == "getPhoneNumber:ok") {
      if (uid) {
        wx.login({
          success: res => {
            var param = {
              'encryptedData': e.detail.encryptedData,
              'iv': e.detail.iv,
              'js_code': res.code
            };
            app.wxRequest('POST', "Index/getUserPhone", param, (res) => {
              var data = res.data;
              that.setData({
                userInfo: data
              })
            }, (err) => {
              console.log(err.errMsg)
            })
          }
        })
      } else {
        wx.navigateTo({
          url: '../authorization/authorization',
        })
      }
    }
  },
  checkUserLogin() {
    var uid = wx.getStorageSync('uid');
    if (!uid) {
      wx.navigateTo({
        url: '../authorization/authorization',
      })
    }
    return false;
  }
})